/*
 * @(#)AlarmNoticeLogImpl.java   1.0  2022年3月11日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.monitor.core.alarm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.swift.core.log.LogPrintlnUtil;
import com.swift.core.log.LogPrintlnUtil.LogTitle;
import com.swift.core.log.LogPrintlnUtil.LogUnit;
import com.swift.monitor.core.point.AlarmLevel;
import com.swift.monitor.core.point.JvmPoint;

/**
 * 添加说明
 * 
 * @author zhengjiajin
 * @version 1.0 2022年3月11日
 */
@Component
public class AlarmNoticeJvmLogImpl implements AlarmNotice<JvmPoint> {

    private static final Logger log = LoggerFactory.getLogger(AlarmNoticeJvmLogImpl.class);

    /**
     * @see com.swift.monitor.core.alarm.AlarmNotice#alarm(com.swift.monitor.core.point.Point)
     */
    @Override
    public void alarm(JvmPoint point) {
        List<LogTitle> logTitleList = new ArrayList<LogTitle>();
        logTitleList.add(new LogTitle("startTime", 20, "startTime"));
        logTitleList.add(new LogTitle("sysCpuLate", 10, "sysCpuLate",LogUnit.PRE));
        logTitleList.add(new LogTitle("jvmCpuLate", 10, "jvmCpuLate",LogUnit.PRE));
        logTitleList.add(new LogTitle("maxMemory", 10, "maxMemory",LogUnit.M));
        logTitleList.add(new LogTitle("useMemory", 10, "useMemory",LogUnit.M));
        logTitleList.add(new LogTitle("memoryLate", 10, "memoryLate",LogUnit.PRE));
        logTitleList.add(new LogTitle("runThreadCount", 20, "runThreadCount"));
        logTitleList.add(new LogTitle("lockThreadCount", 20, "lockThreadCount"));
        String logInfo = LogPrintlnUtil.println(point.getAlarmInfo(),logTitleList, Arrays.asList(point));
        if (AlarmLevel.ERROR.equals(point.getLevel())) {
            log.error(logInfo);
        }
        if (AlarmLevel.WARN.equals(point.getLevel())) {
            log.warn(logInfo);
        }
        if (AlarmLevel.INFO.equals(point.getLevel())) {
            log.info(logInfo);
        }
    }

}
